#coding=utf-8
from os import path
import configparser
#获取配置文件内容
def get_config(file,mode,card_name):
    """
    file #选择一个配置文件
    mode  #选择一个section(部分)
    card_name #网卡名
    """
    if path.isfile(file):
        net_config = configparser.ConfigParser()
        net_config.read(file,encoding='utf-8')
        # Intranet = net_config.items(mode)
        IP = net_config.get(mode,"IP")
        GATEWAY = net_config.get(mode,"GATEWAY")
        NETMASK = net_config.get(mode,"NETMASK")
        DNS1 = net_config.get(mode,"DNS1")
        DNS2 = net_config.get(mode,"DNS2")
        print(IP)
        print(GATEWAY)
        print(NETMASK)
        print(DNS2)
        print(DNS1)
        # config(card=card_name, ip=IP, netmask=NETMASK, gateway=GATEWAY, dns1=DNS1, dns2=DNS2)
    else:
        print("文件[ %s ]不存在" %file)
get_config(file='./connect.conf', mode='Intranet', card_name='VMware Network Adapter VMnet1')